<template>
     <drawerlayout
      ref="drawer"
      style="width:750px"
      leftWidth="500px"
      :isOpen="open"
      >
      <wraper>
          <side-bar></side-bar>
      </wraper>
      <wraper>
        <host style="flex: 1"  :page="index">
          <home-index ref="home"  class="main"></home-index>
          <wallet-index ref="wallet"  class="main"></wallet-index>
          <trade-index ref="trade"  class="main"></trade-index>
          <!-- <find-index  class="main" ></find-index> -->
        </host>
        <tab-bar :style="style" @tabTo="onTabTo" :pIndexKey="index"></tab-bar>
       </wraper>
     </drawerlayout>
</template>
<script>
import TradeIndex from '../trade/index.vue'
import WalletIndex from '../wallet/index.vue'
import FindIndex from '../find/index.vue'
import HomeIndex from '../home/home.vue'
import PriceIndex from '../price/index.vue'
import MyIndex from '../my/index.vue'
import SideBar from '../../component/sidebar.vue'
import TabBar from '../../component/tabbar.vue'
import Utils from '../../utils/index.js'
export default {
  name: 'index',
  data () {
    return {
      index:0,
      cancelUpdate:false,
      open:false
    }
  },
  components: {TradeIndex,WalletIndex,FindIndex,PriceIndex,HomeIndex,SideBar,TabBar},
  created() {
    const notify = weex.requireModule('notify');
      notify.regist('themeChange',(data)=>{
        this.$forceUpdate()
      })
      notify.regist("toggle_slider", ()=> {
        this.$refs.drawer.toggle();
      });
  },
  methods: {
    onLoad(){
      var page=weex.requireModule("page")
      page.doubleBack()
      // 初始化home数据
     this.$refs.home.init()
     this.$refs.wallet.init()
     this.check_updater()
    },
    onTabTo(_result){
     this.index = _result.data.key;
    },
    // 检测更新
   check_updater(){
     let app;
     var env=weex.requireModule('env')
     var updater=weex.requireModule('updater')
     var device=weex.requireModule('device')
     Utils.isIOS() ? app = 2 : app = 1
      this.$http.getSilent('index/checkupdate',{appType:app,appNumber:env.versionCode()},(res)=>{
        if(res.result){
        this.modal.confirm({message:'当前已有新版本，是否更新',okTitle:'更新',cancelTitle:'下次再说'},(val)=>{
          if(val === '更新'){
            this.toast('AXSwap已在后台下载,请在控制栏中查看进度。')
            Utils.isIOS() ? device.openUrl(res.result) : updater.download(res.result)
          }else{
            this.cancelUpdate = true
          }
        })
        }
      })  
   }
  }
}
</script>
<style  scoped>
 .main{
   width: 750px;
   position: absolute;
   top: 0;
   left: 0;
   bottom: 0;
 }
</style>
